package com.xunji.user.common;

public class TokenUtils {

    public static final String CACHE_DELIMITER = "_";

    public static final String SESSION_PREFIX = "LOGINSESSION";

    /**
     * 登录会话key
     *
     * @param userId
     * @param from
     * @return
     */
    public static String genSessionKey(String userId, String from) {
        return SESSION_PREFIX + CACHE_DELIMITER + userId + CACHE_DELIMITER + from;
    }

    public static String getUserId(String token) {
        String cacheVal = Token.getInstance().getUsername(token);
        String[] split = cacheVal.split(CACHE_DELIMITER, 3);
        if (split.length < 2) return null;
        return split[1];
    }
}
